package org.example.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.example.entity.VideoParseRecord;

import java.util.List;

@Mapper
public interface VideoParseRecordMapper extends BaseMapper<VideoParseRecord> {
    
    /**
     * 根据昵称查询解析记录
     */
    @Select("SELECT * FROM video_parse_records WHERE nickname = #{nickname} ORDER BY create_time DESC")
    List<VideoParseRecord> getRecordsByNickname(String nickname);
    
    /**
     * 根据解析状态查询记录
     */
    @Select("SELECT * FROM video_parse_records WHERE parse_status = #{parseStatus} ORDER BY create_time DESC")
    List<VideoParseRecord> getRecordsByParseStatus(Integer parseStatus);
    
    /**
     * 根据平台查询记录
     */
    @Select("SELECT * FROM video_parse_records WHERE platform = #{platform} ORDER BY create_time DESC")
    List<VideoParseRecord> getRecordsByPlatform(String platform);
    
    /**
     * 根据昵称和解析状态查询记录
     */
    @Select("SELECT * FROM video_parse_records WHERE nickname = #{nickname} AND parse_status = #{parseStatus} ORDER BY create_time DESC")
    List<VideoParseRecord> getRecordsByNicknameAndStatus(String nickname, Integer parseStatus);
    
    /**
     * 根据昵称和平台查询记录
     */
    @Select("SELECT * FROM video_parse_records WHERE nickname = #{nickname} AND platform = #{platform} ORDER BY create_time DESC")
    List<VideoParseRecord> getRecordsByNicknameAndPlatform(String nickname, String platform);
    
    /**
     * 查询成功解析的记录
     */
    @Select("SELECT * FROM video_parse_records WHERE parse_status = 1 ORDER BY create_time DESC")
    List<VideoParseRecord> getSuccessRecords();
    
    /**
     * 查询失败解析的记录
     */
    @Select("SELECT * FROM video_parse_records WHERE parse_status = 0 ORDER BY create_time DESC")
    List<VideoParseRecord> getFailedRecords();
    
    /**
     * 分页查询记录
     */
    @Select("SELECT * FROM video_parse_records ORDER BY create_time DESC LIMIT #{offset}, #{size}")
    List<VideoParseRecord> getRecordsWithPage(Integer offset, Integer size);
    
    /**
     * 统计总记录数
     */
    @Select("SELECT COUNT(*) FROM video_parse_records")
    Integer getTotalCount();
    
    /**
     * 统计成功解析的记录数
     */
    @Select("SELECT COUNT(*) FROM video_parse_records WHERE parse_status = 1")
    Integer getSuccessCount();
    
    /**
     * 统计失败解析的记录数
     */
    @Select("SELECT COUNT(*) FROM video_parse_records WHERE parse_status = 0")
    Integer getFailedCount();
    
    /**
     * 根据昵称统计记录数
     */
    @Select("SELECT COUNT(*) FROM video_parse_records WHERE nickname = #{nickname}")
    Integer getCountByNickname(String nickname);
    
    /**
     * 根据平台统计记录数
     */
    @Select("SELECT COUNT(*) FROM video_parse_records WHERE platform = #{platform}")
    Integer getCountByPlatform(String platform);
} 